/**
 * 
 */
package se.ricardo.gamesorgs.api.common;

import java.util.ArrayList;
import java.util.List;

/**
 * Enum for storing the available condition values.
 * <br>
 * 
 * @author Ricardo Ocaña Leal
 *
 */
public enum ConditionScale {
	MISSING("", 0),
	VP("Very Poor", 1),
	P("Poor", 2),
	G("Good", 3),
	VG("Very Good", 4),
	NM("Near Mint", 5),
	M("Mint", 6);

	// Store the string value of the enum element.
	private String value;
	// Store the index of the enum.
	private int index;

	/**
	 * Constructor for each enum element.<br>
	 * Takes a String value for each element.
	 * <br>
	 * 
	 * @param
	 * v The String value of the element.
	 * */
	private ConditionScale(String v, int i) {
		value = v;
		index = i;
	}

	/**
	 * Returns the String value of a specific enum value.
	 * <br>
	 * 
	 * @param
	 * c The enum element to get the String value for.
	 * <br>
	 * 
	 * @return
	 * The String value.
	 * */
	private static String getValue(ConditionScale c) {
		return c.value;
	}
	
	/**
	 * Returns the index of the enum element.
	 * <br>
	 * 
	 * @param
	 * c The enum element to get the index for.
	 * <br>
	 * 
	 * @return
	 * The elements index.
	 * */
	private static int getIndex(ConditionScale c) {
		return c.index;
	}
	
	/**
	 * Returns a {@link List} with the String values of all the
	 * enum elements.
	 * <br>
	 * 
	 * @return
	 * The List with the values.
	 * */
	public static List<String> getConditionList() {
		List<String> conditionList = new ArrayList<>();

		for(ConditionScale c : values()) {
			conditionList.add(getValue(c));
		}

		return conditionList;
	}
	
	/**
	 * Returns a String array with the String values of all the
	 * enum elements.
	 * <br>
	 * 
	 * @return
	 * The String array with the values.
	 * */
	public static String[] getConditionArray() {
		List<String> tempList = getConditionList();
		String[] conditionArray = new String[tempList.size()];

		for(int i=0; i<tempList.size(); i++) {
			conditionArray[i] = tempList.get(i);
		}

		return conditionArray;
	}
	
	/**
	 * Returns the index of a condition scale element with the
	 * matching value of the parameter.
	 * <br>
	 * 
	 * @param
	 * value The enum element value to match.
	 * <br>
	 * 
	 * @return
	 * The index of the enum element.
	 * */
	public static int getConditionIndex(String value) {
		for(ConditionScale c : values()) {
			if(getValue(c).equals(value)) {
				return getIndex(c);
			}
		}
		
		return 0;
	}
}
